package cst.a305htr.fragmenttest305htr.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import cst.a305htr.fragmenttest305htr.Adapter.MyAdapter;
import cst.a305htr.fragmenttest305htr.Iface.ArticleListener;
import cst.a305htr.fragmenttest305htr.Model.ArticleModel;
import cst.a305htr.fragmenttest305htr.R;
import cst.a305htr.fragmenttest305htr.bean.ArticleBean;

/**
 * A simple {@link Fragment} subclass.
 */
public class WeixinFragment extends Fragment{
    private View view;
    private Context context;
    private List<ArticleBean> list;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;
    ArticleListener articleListener=new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> listt) {
            list = listt;
            mAdapter.setList(list);
            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context, "fail" + msg, Toast.LENGTH_SHORT);
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        context=getActivity();
        view=inflater.inflate(R.layout.wfragment,container,false);
        recyclerView=(RecyclerView)view.findViewById(R.id.recyclerview);
        initRecyclerView();
        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"2ts2j910hv4m270hipde4a67d7",articleListener);
        return view;
    }

    private void initRecyclerView() {
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        //list=getData();
        mAdapter=new MyAdapter(context);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);
    }
}
